﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace _7.URLExtraction
{
    class Program
    {
        static void Main(string[] args)
        {
            string text = "www.abv.bg http://abv.bg abv.bg www./k.k";

            ExtraxtURL(text);
        }

        public static void ExtraxtURL(string text)
        {
            string pattern = @"(\A|\b)(www\.|http://)[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*(\.\w{2,4})";

            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);

            MatchCollection matches = regex.Matches(text);

            foreach (Match match in matches)
            {
                Console.WriteLine(match.Value + " at " + match.Index);
            }
        }
    }
}
